package com.zxc.project.base;

import cn.hutool.core.bean.BeanUtil;

import java.lang.reflect.ParameterizedType;

/**
* @author zxc_user
* @date 2021/3/3 21:39
* @version 1.0
* @description 基础请求对象
**/
public abstract class BaseRequest<T extends BaseEntity> {

    protected Class<T> clazz;

    public BaseRequest() {
//        clazz = (Class<T>) TypeUtil.getClass(this.getClass().getGenericSuperclass());
        this.clazz = (Class<T>) ((ParameterizedType) getClass().getGenericSuperclass()).getActualTypeArguments()[0];
    }

    public T getPojo() {
        return getPojo(false);
    }

    public T getPojo(boolean updateTime) {
        T toBean = BeanUtil.toBean(this, clazz);
        toBean.init(updateTime);
        return toBean;
    }
}
